package com.cntaiping.royal.bass.core.controller;

import com.cntaiping.royal.bass.common.getopenid.WxUtils;
import com.cntaiping.royal.bass.core.entity.ModelData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author jiangwei
 * @since 20/2/22
 */
@RestController
@RequestMapping("wechat")
public class WeChatController {

    private final static Logger logger= LoggerFactory.getLogger(WeChatController.class);


    @GetMapping(value = "/getOpenId", produces = {"application/json;charset=UTF-8"})
    public Object getOpenId(@RequestParam(value = "code", required = false)String code){

        ModelData modelData = new ModelData();

        logger.info("code为:"+code);

        if (code == null) {
            modelData.setMsg("获取openid失败");
            modelData.setSuccess(false);
        }else {
            modelData.setSuccess(true);
            modelData.setMsg("获取openid成功");
            String openid = WxUtils.getopendid(code);

            logger.info("openid为:"+openid);

            modelData.setjData(openid);
        }

        return modelData;
    }
}
